#include "RBTree.h"

namespace fuh
{
    template<class K,class V,class Compare = DefaultCmp<K>> 
    class map{
        typedef pair<const K,V> KV_field;
        struct MapKey{

            const K& operator()(const KV_field& t)const{
                return t.first;
            }
        };
        RBTree<K,KV_field,MapKey,Compare> m_tree;
    public:
        
        typedef typename RBTree<K,KV_field,MapKey,Compare>::iterator iterator;//这里不加typename，编译器会报错
        typedef typename RBTree<K,KV_field,MapKey,Compare>::const_iterator const_iterator;//这里不加typename
        iterator begin(){
            return m_tree.begin();
        }
        iterator end(){
            return m_tree.end();
        }
        const_iterator cbegin()const{
            return m_tree.begin();
        }
        const_iterator cend()const{
            return m_tree.end();
        }
        pair<iterator,bool> insert(const K& key,const V& value){
            return m_tree.insert(KV_field(key,value));
        }
        V& operator[](const K& key)
        {
            return insert(key,V()).first->second;
        }
       
    }; 
} // namespace fuh
